package truef.favoriteshop.domain;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import edu.zut.cs.software.base.domain.BaseTreeEntity;

@Table(name = "T_ADMIN_FAVORITE")
@Entity
@NamedQueries({ @NamedQuery(name = "Favorite.getRoot", query = "select g from Favorite g where g.parent is null") })
public class Favorite extends BaseTreeEntity<Favorite>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1186734764624062835L;
	@OneToMany(mappedBy = "favorite", cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
	Set<Shop> shops;
	@Column(name = "name")
	String name;
	@Column(name = "url")
	String url = "null";
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
		choose();
	}
	public void changeName(String name) {
		this.name=name;
	}
	private void choose() {
		if (name.equals("favorite")) {
			url = null;
		}else if(name.equals("webFlag")) {
			String u = "/java";
			setUrl(u);
			url = getUrl();
		}else {
			
		}
	}
	public void setUrl(String url) {
		this.url=url;
	}
	public String getUrl() {
		return url;
	}
}
